// Tests getWinners()

#include "dominion.h"
#include "dominion_helpers.h"
#include <string.h>
#include <stdio.h>
#include <assert.h>
#include "rngs.h"

// set NOISY_TEST to 0 to remove printfs from output
#define NOISY_TEST 1

// set BOUNDARY_TEST to 0 to exclude boundary test cases.
#define BOUNDARY_TEST 0

int getCost(int cardNumber);

int main(int argc, char *argv[]) {
    int i;
    int seed = 1000;
    int numPlayer = 2;
    int maxBonus = 10;
    int p, r, handCount;
    int bonus;
    int k[10] = {adventurer, council_room, feast, gardens, mine
        , remodel, smithy, village, baron, great_hall};
    struct gameState G;
    int maxHandCount = 5;
    int player;
    int winner;
    int n;
    
    // arrays of all coppers, silvers, and golds
    int coppers[MAX_HAND];
    int silvers[MAX_HAND];
    int golds[MAX_HAND];
    int players[numPlayer];
    int hand1[MAX_HAND];
	int hand2[MAX_HAND];
	int hand3[MAX_HAND];
    
    for (i = 0; i < MAX_HAND; i++)
    {
        hand1[i] = province;
		hand2[i] = curse;
        hand3[i] = duchy;
    }
    
    printf ("TESTING getWinners():\n\n");
    
    for (p = 2; p <= numPlayer; p++)
    {
       	for (handCount = 1; handCount <= maxHandCount; handCount++)
		{
#if (NOISY_TEST == 1)
			printf("Test for a game winner with %d players.\n", numPlayer);
#endif
			memset(&G, 23, sizeof(struct gameState));   // clear the game state
			r = initializeGame(p, k, seed, &G); // initialize a new game
            
			for (player = 0; player < p; player++)
			{
				G.handCount[player] = handCount;    // set the number of cards on hand
				switch (player)
				{
					case 0:
						memcpy(G.hand[player], hand1, sizeof(int) * handCount); // set all the cards to hand 2 cards
						break;
					case 1:
						memcpy(G.hand[player], hand2, sizeof(int) * handCount); // set all the cards to hand 2 cards
						break;
					case 2:
						memcpy(G.hand[player], hand3, sizeof(int) * handCount); // set all the cards to hand 3 cards
						break;
					default:
						break;
				}
                
#if (NOISY_TEST == 1)
       			printf("Score for player %d = %d\n", player, scoreFor(player,&G));
#endif
       		}
       		
       		// The winner
       		for(n = 0; n < numPlayer; n++)
       		{
       			if(players[n] == 1)
       				winner = n;
       		}
    
#if (NOISY_TEST == 1)
                printf("Winner is: player %d\n", winner);
                printf("Expected winner is: player %d\n\n", player - 2);
#endif
                assert(winner == player - 2);
            }
        }
                
    
    printf("All tests passed!\n");
    
    return 0;
}